<?php
/*
 * @Descripttion:
 * @version:
 * @Author: YouHuJun
 * @Date: 2022-02-12 10:43:36
 * @LastEditors: youhujun 2900976495@qq.com
 * @LastEditTime: 2025-02-25 15:02:02
 */

namespace YouHuJun\LaravelFastApi\App\Providers;

use Illuminate\Support\ServiceProvider;

class PublishServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {

    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
       $this->registerPublish();
    }

    /**
     * 注册发布
     *
     * @return void
     */
    protected function registerPublish()
    {
       if ($this->app->runningInConsole())
       {
		   //发布开发模版
		   //前提是执行了 php artisan 
		   $this->publishStub();
		   
		   //开发初始化发布
		   $this->publishInit();

		   //发布配置文件
		   $this->publishConfig();

		   //发布数据填充
		   $this->publishDBSeeders();

		   //发布中间件
		   $this->publishMiddleware();
		  
		   //发布路由
		   $this->publishRoute();

		   //发布自定义验证规则
           $this->publishRules();
		   
		   //发布控制器
           $this->publishController();

		   //发布响应资源
		   $this->publishResource();

		   //发布模型
           $this->publishModels();

		   //发布门面代理
           $this->publishFacade();

		   //发布门面服务
           $this->publishFacadeService();

		   //发布事件
           $this->publishEvent();

		   //发布事件监听
           $this->publishListen();

		   //发布授权策略
           $this->publishPolicy();

		   //发布异常
           $this->publishException();

		   //发布消息通知
           $this->publishNotification();

		   //发布队列任务
           $this->publishJob();

		   //发布模版
		   $this->publishStub();

		   //发布命令
           $this->publishCommand(); 
       }
    }

	/**
	 * 发布替换模版
	 */
	protected function publishStub()
	{
		$this->publishes([
            //发布任务
             __DIR__.'/../../stubs' => base_path('stubs'),
            ],'init');

		$this->publishes([
            //发布任务
             __DIR__.'/../../stubs' => base_path('stubs'),
            ],'cover');
		
		//二次安装单独发布
		$this->publishes([
            //发布任务
             __DIR__.'/../../stubs' => base_path('stubs'),
            ],'stub');
	}

    /**
     * 发布初始文件
     *
     * @return void
     */
    protected function publishInit()
    {
		//初始化
		$this->publishes([
			//发布门面,契约和与之对应的服务层
            __DIR__.'/../../Publish/laravel-echo-server'=>base_path('laravel-echo-server'),
            __DIR__.'/../../Publish/laravel-echo-server.json.example'=>base_path('laravel-echo-server.json.example')
		],'init');

		//发布计划任务
		$this->publishes([
            __DIR__.'/../../Publish/cron/'=>base_path('cron'),
		],'init');

		$this->publishes([
            //发布基础使用文档
            __DIR__.'/../../Publish/Documents/'=>base_path('Documents'),
		],'init');

		//初始开发项目需要发布的
		$this->publishes([
            //发布基础使用文档
            __DIR__.'/../../Publish/.gitignore'=>base_path('.gitignore'),
		],'init');

		$this->publishes([
			 //发布环境变量模板文件
            __DIR__.'/../../Publish/.env.example'=>base_path('.env.example'),

		],'int');

		$this->publishes([
            //发布基础资源 项目默认图片
            __DIR__.'/../../Publish/public/config'=>storage_path('app/public/config'),
            //发布默认的excel模板
            __DIR__.'/../../Publish/public/excel'=>storage_path('app/public/excel'),
        ],'init');

		//覆盖发布

		//初始开发项目需要发布的
		$this->publishes([
            //发布基础使用文档
            __DIR__.'/../../Publish/.gitignore'=>base_path('.gitignore'),
		],'cover');

		$this->publishes([
			 //发布环境变量模板文件
            __DIR__.'/../../Publish/.env.example'=>base_path('.env.example'),

		],'cover');

		
		$this->publishes([
            //发布基础资源 项目默认图片
            __DIR__.'/../../Publish/public/config'=>storage_path('app/public/config'),
            //发布默认的excel模板
            __DIR__.'/../../Publish/public/excel'=>storage_path('app/public/excel'),
        ],'cover');

		//二次开发使用用来
		$this->publishes([
            //发布基础资源 项目默认图片
            __DIR__.'/../..//Publish/public/config'=>storage_path('app/public/config'),
            //发布默认的excel模板
            __DIR__.'/../..//Publish/public/excel'=>storage_path('app/public/excel'),
        ],'static');
    }


	/**
	 * 发布配置文件到应用的配置目录。
	 *
	 * 此方法将指定的配置文件发布到 Laravel 应用的配置目录中，
	 * 以便在应用中使用自定义配置。
	 *
	 * @return void
	 */
	protected function publishConfig()
	{
		//初始化
		$this->publishes([
			 //发布配置文件
			 __DIR__.'/../../Publish/config/help.php'=>config_path('help.php'),
			 __DIR__.'/../../Publish/config/app.php'=>config_path('app.php'),
			 __DIR__.'/../../Publish/config/auth.php'=>config_path('auth.php'),
			 __DIR__.'/../../Publish/config/broadcasting.php'=>config_path('broadcasting.php'),
			 __DIR__.'/../../Publish/config/database.php'=>config_path('database.php'),
			 __DIR__.'/../../Publish/config/logging.php'=>config_path('logging.php'),
			 __DIR__.'/../../Publish/config/mail.php'=>config_path('mail.php'),
			 __DIR__.'/../../Publish/config/queue.php'=>config_path('queue.php'),
            __DIR__.'/../../Publish/config/custom'=>config_path('custom'),
		],'init');

		//覆盖
		$this->publishes([
			 //发布配置文件
			 __DIR__.'/../../Publish/config/help.php'=>config_path('help.php'),
			 __DIR__.'/../../Publish/config/app.php'=>config_path('app.php'),
			 __DIR__.'/../../Publish/config/auth.php'=>config_path('auth.php'),
			 __DIR__.'/../../Publish/config/broadcasting.php'=>config_path('broadcasting.php'),
			 __DIR__.'/../../Publish/config/database.php'=>config_path('database.php'),
			 __DIR__.'/../../Publish/config/logging.php'=>config_path('logging.php'),
			 __DIR__.'/../../Publish/config/mail.php'=>config_path('mail.php'),
			 __DIR__.'/../../Publish/config/queue.php'=>config_path('queue.php'),
            __DIR__.'/../../Publish/config/custom'=>config_path('custom'),
		],'cover');
	}

	/**
     * 发布数据填充
     *
     * @return void
     */
    protected function publishDBSeeders()
    {
		//单独发布 数据填充
        $this->publishes([
            __DIR__.'/../../Publish/database/seeders'=>database_path('seeders'),
        ],'init');

        //单独发布 数据填充
        $this->publishes([
            __DIR__.'/../../Publish/database/seeders'=>database_path('seeders'),
        ],'cover');

    }


	/**
	 * 发布中间件
	 */
	public function publishMiddleware()
	{
		$this->publishes([
        //发布中间件
         __DIR__.'/../../Publish/app/Http/Middleware'=>app_path('Http/Middleware'), 
        ],'init'); 

	}
    

    /**
     * 发布路由
     *
     * @return void
     */
    protected function publishRoute()
    {
        //php artisan vendor:publish --tag=youhujun
        $this->publishes([
        //发布路由文件
        __DIR__.'/../../Publish/routes/api'=>base_path('routes/api'),
        
        ],'init'); 

    }

    /**
     * 发布自定义请求规则
     *
     * @return void
     */
    protected function publishRules()
    {
        $this->publishes([
            //发布控制器需要的自定义验证规则
            __DIR__.'/../../Publish/app/Rules'=>app_path('Rules'),
        ],'init');
    }

    /**
     * 发布自定义控制器
     *
     * @return void
     */
    protected function publishController()
    {
        $this->publishes([
            //发布控制器
            //测试用
            __DIR__.'/../../Publish/app/Http/Controllers'=>app_path('Http/Controllers'),

        ],'init');

    }

	/**
	 * 发布响应资源api控制
	 *
	 * @return void
	 */
	protected function publishResource()
	{
		  $this->publishes([

			//发布模版
            __DIR__.'/../../Publish/app/Http/Resources'=>app_path('Http/Resources'),
         
		  ],'init');
	}

    /**
     * 发布数据库
     *
     * @return void
     */
    protected function publishModels()
    {
        $this->publishes([
            //模板开发用
             __DIR__.'/../../Publish/app/Models'=>app_path('Models'),
        ],'init');

		$this->publishes([
            //模板开发用
             __DIR__.'/../../Publish/app/Models'=>app_path('Models'),
        ],'cover');
    }

        /**
     * 发布门面代理
     *
     * @return void
     */
    protected function publishFacade()
    {
        //发布门面代理
        $this->publishes([
        //开发模板
         __DIR__.'/../../Publish/app/Facade'=>app_path('Facade'),

        ],'init');
    }

    /**
     * 发布代理门面的服务层
     *
     * @return void
     */
    protected function publishFacadeService()
    {
        $this->publishes([
            __DIR__.'/../../Publish/app/Service' => app_path('Service'),
        ],'init');

    }

    /**
     * 发布事件
     *
     * @return void
     */
    protected function publishEvent()
    {
        $this->publishes([
            __DIR__.'/../../Publish/app/Events' => app_path('Events'),
        ],'init');
    }

    /**
     * 发布监听
     *
     * @return void
     */
    protected function publishListen()
    {
        $this->publishes([
            __DIR__.'/../../Publish/app/Listeners' => app_path('Listeners'),
        ],'init');
    }

    /**
     * 发布授权
     *
     * @return void
     */
    protected function publishPolicy()
    {
        $this->publishes([
             __DIR__.'/../../Publish/app/Policies' => app_path('Policies'),
        ],'init');
    }

    /**
     * 发布自定义异常
     *分析 异常需要直接发布到代码中 否则抛出异常需要频繁判断
     * @return void
     */
    protected function publishException()
    {
        $this->publishes([
             __DIR__.'/../../Publish/app/Exceptions' => app_path('Exceptions'),
        ],'init');

    }

    /**
     * 发布通知
     *
     * @return void
     */
    protected function publishNotification()
    {
        $this->publishes([
             __DIR__.'/../../Publish/app/Notifications' => app_path('Notifications'),
        ],'init');
    }

    /**
     * 发布任务与队列
     *
     * @return void
     */
    protected function publishJob()
    {
        $this->publishes([
            //发布任务
             __DIR__.'/../../Publish/app/Jobs' => app_path('Jobs'),
            ],'init');

    }

	/**
	 * 发布命令
	 */
	protected function publishCommand()
	{
		$this->publishes([
            //发布任务
             __DIR__.'/../../Publish/app/Console' => app_path('Console'),
            ],'init');
	}

}